package com.ias.agdis_r.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;

/**
 * 一个ProgressBar，只有GONE和Visible两种状态，InVisible时改为Gone状态；
 * 提供对可见状态改变的事件监听接口，可通过可见状态执行相应逻辑
 * 
 * @author qibo.yu
 * @version 2015年8月20日 上午9:14:03
 **/
public class MyProgressBar extends ProgressBar {

	public interface OnVisibilityChangeListener {
		void onVisibilityChanged(boolean visibity);
	}

	private OnVisibilityChangeListener onVisibilityChangeListener;

	public OnVisibilityChangeListener getOnVisibilityChangeListener() {
		return onVisibilityChangeListener;
	}

	public void setOnVisibilityChangeListener(OnVisibilityChangeListener onVisibilityChangeListener) {
		this.onVisibilityChangeListener = onVisibilityChangeListener;
	}

	public MyProgressBar(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	public MyProgressBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	public MyProgressBar(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void setVisibility(int v) {

		if (v == View.INVISIBLE) {
			v = View.GONE;
		}

		super.setVisibility(v);

		if (null != onVisibilityChangeListener) {
			boolean visibility = true;
			if (v == View.INVISIBLE || v == View.GONE) {
				visibility = false;
			}
			onVisibilityChangeListener.onVisibilityChanged(visibility);
		}
	}

}
